#!/bin/bash
# 检查Linux图标配置是否完整

echo "======================================"
echo "Notepad-- Linux 图标检查工具"
echo "======================================"
echo ""

ICON_BASE="/Users/dddpeter/myworks/notepad--/src/linux/usr/share/icons/hicolor"
DESKTOP_FILE="/Users/dddpeter/myworks/notepad--/src/linux/usr/share/applications/notepad--.desktop"

# 检查desktop文件
echo "1. 检查desktop文件..."
if [ -f "$DESKTOP_FILE" ]; then
    echo "✓ Desktop文件存在"
    ICON_NAME=$(grep "^Icon=" "$DESKTOP_FILE" | cut -d= -f2)
    echo "  图标名称: $ICON_NAME"
else
    echo "✗ Desktop文件不存在！"
    exit 1
fi

echo ""
echo "2. 检查图标文件..."

# 推荐的图标尺寸
RECOMMENDED_SIZES=(16 22 24 32 48 64 128 256 512)
EXISTING_COUNT=0
MISSING_COUNT=0

for size in "${RECOMMENDED_SIZES[@]}"; do
    ICON_PATH="$ICON_BASE/${size}x${size}/apps/notepad--.png"
    if [ -f "$ICON_PATH" ]; then
        # 验证图标实际尺寸
        if command -v file >/dev/null 2>&1; then
            INFO=$(file "$ICON_PATH" | grep -o "[0-9]* x [0-9]*")
            echo "  ✓ ${size}x${size} - $INFO"
        else
            echo "  ✓ ${size}x${size}"
        fi
        EXISTING_COUNT=$((EXISTING_COUNT + 1))
    else
        echo "  ✗ ${size}x${size} - 缺失（建议添加）"
        MISSING_COUNT=$((MISSING_COUNT + 1))
    fi
done

echo ""
echo "3. 统计信息"
echo "  已有图标: $EXISTING_COUNT / ${#RECOMMENDED_SIZES[@]}"
echo "  缺失图标: $MISSING_COUNT / ${#RECOMMENDED_SIZES[@]}"

echo ""
echo "4. 建议"
if [ $MISSING_COUNT -eq 0 ]; then
    echo "  ✓ 图标配置完整！"
else
    echo "  ⚠ 建议补充缺失的图标尺寸以获得最佳显示效果"
    echo ""
    echo "  可以运行以下命令生成缺失的图标："
    echo "  ./scripts/create-icons.sh"
    echo ""
    echo "  或者手动创建："
    for size in "${RECOMMENDED_SIZES[@]}"; do
        ICON_PATH="$ICON_BASE/${size}x${size}/apps/notepad--.png"
        if [ ! -f "$ICON_PATH" ]; then
            echo "  mkdir -p $ICON_BASE/${size}x${size}/apps"
            echo "  convert $ICON_BASE/128x128/apps/notepad--.png -resize ${size}x${size} $ICON_PATH"
        fi
    done
fi

echo ""
echo "5. 图标缓存"
echo "  安装后需要更新图标缓存（CMakeLists.txt已配置自动更新）："
echo "  - gtk-update-icon-cache -f -t /usr/share/icons/hicolor"
echo "  - update-desktop-database /usr/share/applications"

echo ""
echo "======================================"
echo "检查完成"
echo "======================================"

